Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul availability testing and add expected input languages #69

Merged
merged 2 commits into from
Jan 17, 2025

Conversation

domenic
Copy link
Collaborator

@domenic domenic commented Dec 11, 2024

Remove the ai.languageModel.capabilities() method and its accompanying AILanguageModelCapabilities class. Instead, replace it with:

  • ai.languageModel.availability(options), which takes the same options as ai.languageModel.create(), and returns the corresponding availability.
  • ai.languageModel.params(), which returns the default and max params (currently top-K and temperature).

Additionally, add the expectedInputLanguages option to create() and availability(). The addition of this option to create() allows the web developer to signal the expected input languages ahead of time, allowing the downloading of additional material, or fast-failing if the additional material cannot be supported. The addition of this option to availability() replaces the (await ai.languageModel.capabilities()).languageAvailable() method.

Closes #29; see especially #29 (comment).

See also webmachinelearning/writing-assistance-apis#22 and webmachinelearning/translation-api#31.

Instead, we replace it with createOptionsAvailable() and params()
domenic added a commit to webmachinelearning/writing-assistance-apis that referenced this pull request Jan 17, 2025
* Add options for `expectedInputLanguages`, `expectedContextLanguages`, and `outputLanguage`. The former two are used for downloading additional material and early errors if the web developer's required input/context languages cannot be supported by the browser. The latter gives clarity about what to do given mixed-language inputs.

* Remove the `capabilities()` method and the accompanying `AI*Capabilities` classes. The reasoning is as follows:

  Those classes had three APIs: `available`, `createOptionsAvailable()`, and `languageAvailable()`. `languageAvailable()` wasn't clear if it was talking about input, context, or output languages. Now that we have explicit options for those three, we could fold language availability testing into `createOptionsAvailable()`. But then, we can note that the `available` property is kind of useless, as just knowing that some possible combination of options/languages is supported is not helpful for any known use case. So, the only real functionality we care about is testing whether a given set of options to `create()` is supported.
  
  This was previously done via `(await ai.apiName.capabilities()).createOptionsAvailable()`. We instead expose it via `await ai.apiName.availability()`. This name is a bit clearer, and this design also avoids the complexity where we have to retrieve all the availability information for every combination of options during the call to `capabilities()`, for later sync access. Now we can just retrieve the relevant information during the call to `availability()`.

This was previously discussed in webmachinelearning/prompt-api#29; see especially webmachinelearning/prompt-api#29 (comment). Closes #16.

See also webmachinelearning/prompt-api#69 and webmachinelearning/translation-api#31.
@domenic domenic merged commit 5874683 into main Jan 17, 2025
@domenic domenic deleted the create-options-available branch January 17, 2025 02:40
domenic added a commit to webmachinelearning/translation-api that referenced this pull request Jan 17, 2025
…tector

Add an `expectedInputLanguages` option to language detector creation API. This allows the browser to download relevant material if necessary, or fail-fast if a language the web developer needs to support is not available.

Then, remove the `capabilities()` methods and the accompanying `AI*Capabilities` classes.

* For translator, the only useful capabilities API was `(await ai.translator.capabilities()).languagePairAvailable()`. We simplify this to `await ai.translator.availability()`. This design also avoids the complexity where we have to retrieve all the availability information for every combination of options during the call to `capabilities()`, for later sync access. Now we can just retrieve the relevant information during the call to `availability()`.

  Also, by unifying on using the same options for `create()` and `availability()`, we fix #24.

* For language detector, the capabilities supplied both `(await ai.languageDetector.capabilities()).available` and `(await ai.languageDetector.capabilities()).languageAvailable()`. We simplify this into `await ai.languageDetector.availability()`, which can either take no arguments (emulating `available`) or take the same `{ expectedInputLanguages }` argument as `create()` (emulating `languageAvailable()`).

See also webmachinelearning/writing-assistance-apis#22 and webmachinelearning/prompt-api#69.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clarification on supportsLanguage API
2 participants